/**
 * Initialise package and set version
 */
ExtMVC = Ext.extend(Ext.util.Observable, {
			version							: "0.5b1",

			constructor						: function() {
				ExtMVC.superclass.constructor.apply(this, arguments);

				this.addEvents(
						/**
						 * @event environment-changed
						 * Fired whenever the environment is changed
						 * @param {String} name The name of the new environment
						 * @param {Object} config The configuration of the new environment
						 */
						'environment-changed'
				);

				/**
				 * Set up aliases
				 */
				this.getEnvSettings = this.getCurrentEnvironmentSettings;
			},

			/**
			 * @property currentEnvironment
			 * @type String
			 * The current code environment (defaults to production).  Read-only - use setCurrentEnvironment to change
			 */
			currentEnvironment				: 'production',

			/**
			 * Used internally to manage environment variables... user addEnvironmentSettings and 
			 * getEnvironmentSettings to change
			 */
			environments					: {
				'production'	: {}
			},

			/**
			 * Sets the MVC environment to the specified name.  Usually one of 'production' or 'development'
			 * Ignored if the environment has not yet been defined
			 * @param {String} name The name of the environment to set.
			 */
			setCurrentEnvironment			: function(name) {
				if (this.getEnvironmentSettings(name)) {
					this.currentEnvironment = name;
					this.fireEvent('environment-changed', name, this
									.getEnvironmentSettings(name));
				}
			},

			/**
			 * Returns the name of the current environment
			 * @return {String} The name of the current environment
			 */
			getCurrentEnvironment			: function() {
				return ExtMVC.currentEnvironment;
			},

			/**
			 * Returns settings for the current environment (aliased as getEnvSettings)
			 * @return {Object} The settings for the current environment
			 */
			getCurrentEnvironmentSettings	: function() {
				return this
						.getEnvironmentSettings(this.getCurrentEnvironment());
			},

			/**
			 * Adds settings for a given environment name
			 * @param {String} name The name of the environment to add settings for
			 * @param {Object} config The settings object to apply to this environment
			 */
			addEnvironmentSettings			: function(name, config) {
				ExtMVC.environments[name] = ExtMVC.environments[name] || {};
				Ext.apply(ExtMVC.environments[name], config);
			},

			/**
			 * Retrieves all settings for a given environment (defaults to the current environment)
			 * @param {String} name The name of the environment to get settings from
			 * @return {Object} The settings object for the given environment, or null if not found
			 */
			getEnvironmentSettings			: function(name) {
				name = name || ExtMVC.environment;
				return ExtMVC.environments[name];
			}
		});

ExtMVC = new ExtMVC();